package com.project.market.service.impl;

import com.github.pagehelper.PageHelper;
import com.project.market.db.domain.*;
import com.project.market.db.mapper.MarketCollectMapper;
import com.project.market.db.mapper.MarketSearchHistoryMapper;
import com.project.market.db.mapper.MarketUserMapper;
import com.project.market.service.AdminHistoryService;
import com.project.market.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminHistoryServiceImpl implements AdminHistoryService {
    @Override
    public List<MarketSearchHistory> list(String page, String limit, String sort, String order,String userId,String keyword) {

        SqlSession session = MybatisUtil.getSession();
        MarketSearchHistoryMapper mapper = session.getMapper(MarketSearchHistoryMapper.class);
        MarketSearchHistoryExample example = new MarketSearchHistoryExample();
        MarketSearchHistoryExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);
        if(keyword!=null){
            criteria.andKeywordLike("%" + keyword +"%");
        }
        if(userId!=null && !("".equals(userId))){
            try{
            criteria.andUserIdEqualTo(Integer.valueOf(userId));
            } catch (Exception e) {
                return null;
            }
        }

        List<MarketSearchHistory> list = mapper.selectByExample(example);

        PageHelper.startPage(Integer.valueOf(page),Integer.valueOf(limit));

        session.commit();
        session.close();
        return list;


    }
}
